package com.flash.mongodb.service;

import com.flash.mongodb.domain.RecordLog;
import com.flash.mongodb.mapper.RecordLogDao;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
* @description: TODO
* @author admin
* @date 2023/1/2611:50
* @version 1.0
*/
@Service
public class RecordService {

    @Autowired
    RecordLogDao recordLogDao;

    public List<RecordLog> getRecor(){


        List<RecordLog> all = recordLogDao.findAll();
        return all;
    }

    public void save(RecordLog recordLog){
        RecordLog save = recordLogDao.save(recordLog);
    }


    @XxlJob("deleteLog")
    public void delete(){
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format1 = format.format(date);
        recordLogDao.deleteAllByRecordtimeBefore(format1);
    }
}
